# coding: utf-8
'''
Created on May 26, 2010

@author: guard
'''
from plugin_base import PLUGIN_CATEGORIES, PLUGIN_TYPES, BasePlugin#, PluginsRegister

class GamePointsPlugin(BasePlugin):
    category = PLUGIN_CATEGORIES.GAME
    type = PLUGIN_TYPES.MAIN
    
    full_name = u'Количество очков'
    marker = u'О'
    description = u'Общее количество правильных ответов в игре.'
    
    @staticmethod
    def calculate(game):
        r = {}
        for team_id in game.teams:
            r[team_id] = game.total(team_id)
        return r

def calc_ratings(game):
    ratings = [len(game.teams) + 1] * game.questions_number
    for team_id in game.teams:
        for i in range(game.questions_number):
            ratings[i] -= game.results[team_id][i]    
    return ratings

class GameRatingPlugin(BasePlugin):
    category = PLUGIN_CATEGORIES.GAME
    type = PLUGIN_TYPES.ADDITIONAL
    
    full_name = u'Рейтинг'
    marker = u'Р'
    description = u'Рейтинг всех взятых командой вопросов.'
    
    @staticmethod
    def calculate(game):
        ratings = calc_ratings(game)
        r = {}
        for team_id in game.teams:
            r[team_id] = sum(ratings[i] * game.results[team_id][i]
                             for i in range(game.questions_number))
        return r

class GameRatingMaxPlugin(BasePlugin):
    category = PLUGIN_CATEGORIES.GAME
    type = PLUGIN_TYPES.ADDITIONAL
    
    full_name = u'Максимальный Рейтинг'
    marker = u'Рmax'
    description = u'Макисмальный рейтинг среди взятых командой вопросов.'
    
    @staticmethod
    def calculate(game):
        ratings = calc_ratings(game)
        r = {}
        for team_id in game.teams:
            r[team_id] = max(ratings[i] * game.results[team_id][i]
                             for i in range(game.questions_number))
        return r
